package com.luych.toolbox.common.feign.view.gateway.center;

import com.luych.toolbox.common.enums.MicroInstanceStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

@ApiModel("微服务")
public class ServiceView {

    @ApiModelProperty("服务名称")
    private String name;
    @ApiModelProperty("服务实例")
    private List<InstanceView> instances;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<InstanceView> getInstances() {
        return instances;
    }

    public void setInstances(List<InstanceView> instances) {
        this.instances = instances;
    }

    public long getUpCount() {
        return instances.stream().filter(inst -> MicroInstanceStatus.UP.equals(inst.getStatus())).count();
    }

    public long getDownCount() {
        return instances.stream().filter(inst -> MicroInstanceStatus.DOWN.equals(inst.getStatus())).count();
    }
}
